﻿
/*
data [{latlng,relation,messageHtml}]
where relation is used to index markers: i.e. 0 (you), 1 (friends), 2 (friends of friends)
*/
function fillMap(map, data, markers ) {

    function createMarker(latlng, markerOptions, messageHtml) {
        var _latlng = latlng;
        var _marker = new GMarker(_latlng, markerOptions);
        var _messageHtml = messageHtml;
        GEvent.addListener(_marker,"click", function() {
            map.openInfoWindowHtml(_latlng, _messageHtml);
        });
        return _marker;
    }

    if (data.length > 0) {
        map.setCenter(data[0].latlng, 5);
    } else {
        // if there is no information, load no map markers.
        // BUT initialize in some location and zoom.
        map.setCenter(new GLatLng(0,0), 0);        
    }
    var first = null;
    for(var i=0; i < data.length; i++) {
        var current = data[i];
        var m = createMarker( current.latlng , markers[current.relation] , current.messageHtml );
        map.addOverlay(m);
        if ( i == 0 )
          first = m;
    }
    return first;
}
